*File runs analysis on Add Health Data for "Timing Matters" by Aaron Rosenthal and Christina Farhart

*Reading in the data

	use Timing_Matters_AddHealth_Analysis.dta, clear

*Survey setting the data

	svyset [pw=gswgt3_2]
		
*Generating criminal justice age variable that includes people with no contact

	gen crim_just_age_all=crim_just_cont_age
	replace crim_just_age_all=100 if crim_just_cont_dum==0
	tab crim_just_age_all

*Labeling variables

	label var crim_just_cont_scale "# of times stopped by Police"
	label var cont_10_14 "Stopped 1st before 10-14"
	label var cont_15_18 "Stopped 1st btw. 15-18"
	label var cont_19_25 "Stopped 1st after 18"	
	label var income_w3 "Adult Income"
	label var employment "Employed Full Time"
	label var education "Educational Attainment"
	label var married_w3 "Married"
	label var female "Female"
	label var White "White"
	label var age "Age"
	label var religiosity "Religiosity"
	label var Republican "Republican"
	label var Democrat "Democrat"
	label var ideology "Ideology"
	label var neighb_income_w1 "Income"
	label var neighb_pov_w1 "Poverty Rate"	
	label var income_w1 "Household Income Growing Up"
	label var educ_par_w1 "Parental Education"
	label var union_par_w1 "Parent in Union"
	label var civic_par_w1 "Parent in Civic Org."
	label var urban_w1 "Urbanization"
	label var neighb_black_w1 "Majority Black"		
	
*Creating histogram for left side panel of Figure 1
	
	histogram crim_just_cont_age, discrete percent xtitle(Age) xlabel(0(2)26) scheme(s1mono) /// 
	title("Add Health") ylabel(0(5)20) kdensity
	graph save Histogram_Age_Contact.gph, replace
	graph export Histogram_Age_Contact.pdf, replace		
	
*Running models for Table 1- no age variables included
	
	*Model 1.1
	svy: logit vote crim_just_cont_scale income_w3 employment education married_w3 female White age religiosity Republican Democrat ideology income_w1 educ_par_w1 union_par_w1 civic_par_w1 neighb_pov_w1 neighb_income_w1 urban_w1 neighb_black_w1
	estimates store vote
	
	*Model 1.3
	svy: reg trust_gov_avg crim_just_cont_scale income_w3 employment education married_w3 female White age religiosity Republican Democrat ideology income_w1 educ_par_w1 union_par_w1 civic_par_w1 neighb_pov_w1 neighb_income_w1 urban_w1 neighb_black_w1
	estimates store trust
		
	esttab vote trust, starlevels(^ .1 * 0.05 ** .01 *** .001) ///
	cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons constant), using Table_1_Rough.rtf, replace
		
*Running models for Table 2- bringing in age of first contact variables
		
	*Model 2.1	
	svy: logit vote cont_10_14 cont_15_18 cont_19_25 crim_just_cont_scale income_w3 employment education married_w3 female White age religiosity Republican Democrat ideology income_w1 educ_par_w1 union_par_w1 civic_par_w1 neighb_pov_w1 neighb_income_w1 urban_w1 neighb_black_w1
	estimates store vote_age
		
	*Model 2.3
	svy: reg trust_gov_avg cont_10_14 cont_15_18 cont_19_25 crim_just_cont_scale income_w3 employment education married_w3 female White age religiosity Republican Democrat ideology income_w1 educ_par_w1 union_par_w1 civic_par_w1 neighb_pov_w1 neighb_income_w1 urban_w1 neighb_black_w1			
	estimates store trust_age
			
	esttab vote_age trust_age, starlevels(^ .1 * 0.05 ** .01 *** .001) ///
	cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons constant), using Table_2_Rough.rtf, replace
	

*Creating margins plot for left side panel of Figure 2
		
	svy: reg trust_gov_avg crim_just_cont_scale income_w3 employment /// 
	education married_w3 female White age religiosity Republican ///
	Democrat ideology income_w1 educ_par_w1 union_par_w1 civic_par_w1 /// 
	neighb_pov_w1 neighb_income_w1 urban_w1 neighb_black_w1 i.police_age_cat 
	margins police_age_cat
	marginsplot, recast(bar) ///
	title("Political Trust, Add Health") ytitle("Predicted Level of Trust in Government", size(med)) xtitle("Age When First Stopped by Police") ///
	xlabel(1 "Never Stopped" 2 "Before 15" 3 "Between 15-18" 4 "After 18", labsize(small)) ///
	ylabel(2(.5)4) scheme(s1mono)
	graph save AddHealth_Pol_Trust.gph, replace		
	graph export AddHealth_Pol_Trust.pdf, replace	
	
*Supplemental Appendix

	*Summary statistics for Table A1
		tab vote
		sum trust_gov_avg
		tab crim_just_cont_dum
		sum crim_just_cont_scale
		tab cont_10_14
		tab cont_15_17
		tab cont_18_21
		tab cont_22_25
		mean h3ec2
		tab employment
		mean h3ed1
		tab h3ed1	
		tab married_w3
		tab female
		tab White
		tab Black
		mean age
		tab h3re41
		tab Republican
		tab Democrat
		tab ideology
		tab ideology
		mean pa55
		mean h3ed1
		tab h3ed1
		tab union_par_w1
		tab civic_par_w1
		tab neighb_pov_w1
		tab neighb_income_w1
		tab urban_w1
		tab neighb_black_w1	
		
*Running models for Tables A3 and A4- excluding survey weights

	*Model A3.1
	logit vote crim_just_cont_scale income_w3 employment education married_w3 female White age religiosity Republican Democrat ideology income_w1 educ_par_w1 union_par_w1 civic_par_w1 neighb_pov_w1 neighb_income_w1 urban_w1 neighb_black_w1
	estimates store uw_vote
			
	*Model A3.3
	reg trust_gov_avg crim_just_cont_scale income_w3 employment education married_w3 female White age religiosity Republican Democrat ideology income_w1 educ_par_w1 union_par_w1 civic_par_w1 neighb_pov_w1 neighb_income_w1 urban_w1 neighb_black_w1
	estimates store uw_trust
		
	esttab uw_vote uw_trust, starlevels(^ .1 * 0.05 ** .01 *** .001) ///
	cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons constant), using Table_A3_Rough.rtf, replace
				
	*Model A4.1
	logit vote cont_10_14 cont_15_18 cont_19_25 crim_just_cont_scale income_w3 employment education married_w3 female White age religiosity Republican Democrat ideology income_w1 educ_par_w1 union_par_w1 civic_par_w1 neighb_pov_w1 neighb_income_w1 urban_w1 neighb_black_w1
	estimates store vote_age_app
			
	*Model A4.3
	reg trust_gov_avg cont_10_14 cont_15_18 cont_19_25 crim_just_cont_scale income_w3 employment education married_w3 female White age religiosity Republican Democrat ideology income_w1 educ_par_w1 union_par_w1 civic_par_w1 neighb_pov_w1 neighb_income_w1 urban_w1 neighb_black_w1			
	estimates store trust_age_app
			
	esttab vote_age_app trust_age_app, starlevels(^ .1 * 0.05 ** .01 *** .001) ///
	cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons constant), using Table_A4_Rough.rtf, replace
		
*Running model for Table A5- predicting number of times stopped based on age of first contact
	
	*Model A5.1
	svy: reg crim_just_cont_scale cont_10_14 cont_15_18 income_w3 employment education married_w3 female White age religiosity Republican Democrat ideology income_w1 educ_par_w1 union_par_w1 civic_par_w1 neighb_pov_w1 neighb_income_w1 urban_w1 neighb_black_w1 if crim_just_cont_scale>0		
	estimates store scale
	
	esttab scale, starlevels(^ .1 * 0.05 ** .01 *** .001) ///
	cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons constant), using Table_A5_Rough.rtf, replace	
	
*Running model for Table A6- interacting age of contact with frequency of contact			
	
	*Model A6.1
	svy: reg trust_gov_avg cont_10_14##c.crim_just_cont_scale cont_15_18 cont_19_25 income_w3 employment education married_w3 female White age religiosity Republican Democrat ideology income_w1 educ_par_w1 union_par_w1 civic_par_w1 neighb_pov_w1 neighb_income_w1 urban_w1 neighb_black_w1		
	estimates store scale_interaction
			
	esttab scale_interaction, starlevels(^ .1 * 0.05 ** .01 *** .001) ///
	cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons constant), using Table_A6_Rough.rtf, replace
						
*Running models for Table A7- welfare receipt as an additional control

	*Model A7.1
	logit vote cont_10_14 cont_15_18 cont_19_25 welfare_par_w1 welfare_w3 crim_just_cont_scale income_w3 employment education married_w3 female White age religiosity Republican Democrat ideology income_w1 educ_par_w1 union_par_w1 civic_par_w1 neighb_pov_w1 neighb_income_w1 urban_w1 neighb_black_w1
	estimates store vote_welfare
	
	*Model A7.3
	svy: reg trust_gov_avg cont_10_14 cont_15_18 cont_19_25 welfare_par_w1 welfare_w3 crim_just_cont_scale income_w3 employment education married_w3 female White age religiosity Republican Democrat ideology income_w1 educ_par_w1 union_par_w1 civic_par_w1 neighb_pov_w1 neighb_income_w1 urban_w1 neighb_black_w1			
	estimates store trust_welfare
	
	esttab vote_welfare trust_welfare, starlevels(^ .1 * 0.05 ** .01 *** .001) ///
	cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons constant), using Table_A7_Rough.rtf, replace
					
			
					
